package com.tul.exercise.base.string.regex;

import org.junit.jupiter.api.Test;

import static com.tul.exercise.base.utils.Print.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description 《java编程思想》第13章 示例10：
 * <p>
 * 捕获组
 **/
public class Groups {
    static public final String POEM =
            "Twas brilling, and the slithy toves\n" +
            "Did gyre and gimble in the wabe,\n" +
            "All mimsy were the borogaves.\n" +
            "Beware the Jabberwock , my son,\n" +
            "Thew jaws that bite, the claws that catch.\n" +
            "Beware the Jubjub bird, and shun\n" +
            "The frumious Bandersnatch.";

    @Test
    public void test() {
        String p = "(?m)(\\S+)\\s((\\S+)\\s+(\\S+))$";
        Matcher m = Pattern.compile(p).matcher(POEM);

        while (m.find()) {
            for(int j=0;j<m.groupCount();j++) {
                println("[" + m.group() + "]");
                print("");
            }
        }
    }
}
